/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) 李文友 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef CANBUSMAGANETIC_H
#define CANBUSMAGANETIC_H

#include <qmap.h>
#include "ecattype.h"
#include "canbusmaganeticconfig.h"
#include "canbusdevicedriver.h"

//class CanbusMaganeticConfig;

//class CanbusDeviceDriver;
/**
 * @brief The CanbusMaganetic class can 磁条传感器接口
 */
class CanbusMaganetic
{
public:
    CanbusMaganetic(QString fileNameIn, int aliasIn, int busNumberIn, int deviceIdIn,
                    CanbusDeviceDriver *canbusDriverIn);
    ~CanbusMaganetic();

public:
    int startPdoMode();
    int getAlias();
    int sendMaganeticDataRequestCommand();

    int getSensorRawValueFromBuffer(QVector<bool> & sensorRawValueOut);
    /**
     * @brief getSensorPositionValue
     * @param deviceIdIn
     * @param valueOut
     * @return 1=success, 0= 没有灯亮，　－１＝通讯失败
     */
    int getSensorPositionValue(int deviceIdIn, double &valueOut);

    /**
     * @brief isInitialOkStatus
     * @return
     */
    bool isInitialOkStatus();

    /**
     * @brief setSensorDeviceId
     * @param primaryIdIn
     * @param targetIdIn
     * @return
     */
    int setSensorDeviceId(int primaryIdIn, int targetIdIn, int busNumberIn);

    int updateData();

    int getDeviceAddressInfo(int& aliasOut, int& busNumberOut, int& deviceIdOut);
    int getVendorId();
    int downloadSdoConfig();

private:
    int processDataFrame(QVector<bool> & sensorRawValueReturn);
    int processDataFrame_XinSong(QVector<bool> & sensorRawValueReturn);
    int processDataFrame_YuanBen(QVector<bool> & sensorRawValueReturn);
    int getSensorRawValue(QVector<bool> &sensorRawValueReturn);

protected:
    int initial(QString fileName);


private:


    bool sensorRawValue[16];
    CanbusMaganeticConfig* driverConfig;
    int alias;
    int busNumber;
    int deviceId;
    bool isInitialedOk;

    RegConfig regConfig;
    RegAddressInfo regAdd;
    E_VENDOR_ID vendorId;

    CanbusDeviceDriver *canbusDriver;
    QVector<SdoConfig> sdoConfigList;



};

#endif // CANBUSMAGANETIC_H
